<?php
//助餐点相关

namespace App\Http\Controllers\Manage;

use App\Http\Controllers\BaseController;
use App\Services\Manage\RestaurantManageService;
use Illuminate\Http\Request;

class RestaurantController extends BaseController
{

    private RestaurantManageService $restaurantManageService;

    public function __construct(RestaurantManageService $restaurantManageService)
    {
        $this->restaurantManageService = $restaurantManageService;
    }

    /**
     * 助餐点列表
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function list(Request $request)
    {
        $data = $request->all();
        $page = $request->get('page', 1);
        $pageSize = $request->get('page_size', 20);

        $res = $this->restaurantManageService::list($data, $page, $pageSize);

        return $this->success($res);
    }

    /**
     * 助餐点基本信息
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function baseInfo(Request $request)
    {
        $restaurantId = $request->get('restaurant_id', 0);

        $res = $this->restaurantManageService::baseInfo($restaurantId);

        return $this->success($res);
    }

    /**
     * 审核状态更新
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateAuthStatus(Request $request)
    {
        $restaurantId = $request->post('restaurant_id', 0);
        $status = $request->post('status', 0); //审核状态：10为待审核，20为审核失败，30为通过审核待上线，40为已下线，50为已上线
        $reason = $request->post('reason', '');
        $mchid = $request->post('mchid', ''); //商户号

        $res = $this->restaurantManageService::updateAuthStatus($restaurantId, $status, $reason, $mchid);
        if ($res['errcode']) {
            return $this->error($res['errcode'], $res['errmsg']);
        }

        return $this->success([], $res['errmsg']);
    }

    /**
     * 用餐记录列表
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function dinnerLogList(Request $request)
    {
        $data = $request->all();
        $page = $request->get('page', 1);
        $pageSize = $request->get('page_size', 20);

        $res = $this->restaurantManageService::dinnerLogList($data, $page, $pageSize);

        return $this->success($res);
    }

    /**
     * 用餐记录导出
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function dinnerLogListExport(Request $request) {
        $data = $request->all();
        $res = $this->restaurantManageService::dinnerLogListExport($data);

        return $this->success($res);
    }

    /**
     * 助餐点结算-未结算列表
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function unSettleAccountList(Request $request)
    {
        $data = $request->all();
        $page = $request->get('page', 1);
        $pageSize = $request->get('page_size', 20);

        $res = $this->restaurantManageService::unSettleAccountList($data, $page, $pageSize);

        return $this->success($res);
    }

    /**
     * 助餐点待结算详情
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function unSettleAccountInfo(Request $request)
    {
        $restaurantId = $request->get('restaurant_id', 0);

        $res = $this->restaurantManageService::unSettleAccountInfo($restaurantId);

        return $this->success($res);
    }

    /**
     * 结算助餐点账单
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function settleAccountOperate(Request $request)
    {
        $restaurantId = $request->post('restaurant_id', 0);
        $money = $request->post('money', 0);
        $pic = $request->post('pic', '');

        $res = $this->restaurantManageService::settleAccountOperate($restaurantId, $money, $pic);
        if ($res['errcode']) {
            return $this->error($res['errcode'], $res['errmsg']);
        }

        return $this->success([], $res['errmsg']);
    }

    /**
     * 助餐点结算-已结算列表
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function settledAccountList(Request $request)
    {
        $data = $request->all();
        $page = $request->get('page', 1);
        $pageSize = $request->get('page_size', 20);

        $res = $this->restaurantManageService::settledAccountList($data, $page, $pageSize);

        return $this->success($res);
    }

    /**
     * 助餐点已结算详情
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function settledAccountInfo(Request $request)
    {
        $billId = $request->get('bill_id', 0);

        $res = $this->restaurantManageService::settledAccountInfo($billId);

        return $this->success($res);
    }

    /**
     * 助餐点列表标签统计
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function listLabelStatistic(Request $request)
    {
        $activityId = $request->get('activity_id');

        $res = $this->restaurantManageService::listLabelStatistic($activityId);

        return $this->success($res);
    }

    /**
     * 助餐点结算列表标签统计
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function settledAccountListLabelStatistic(Request $request)
    {
        $activityId = $request->get('activity_id');

        $res = $this->restaurantManageService::settledAccountListLabelStatistic($activityId);

        return $this->success($res);
    }


}